const path = require('path')
const webpack = require("webpack")
// const { CleanWebpackPlugin } = require("clean-webpack-plugin")
const HtmlWebpackPlugin = require("html-webpack-plugin")
// const CopyWebpackPlugin = require("copy-webpack-plugin")

module.exports = {
  mode:"none",
  entry:"./src/index.js",
  output:{
    filename:"bundle.js",
    path:path.join(__dirname,'dist'),
    // publicPath:'dist/'
  },
  // devtool:'source-map',
  devtool:'eval',
  devServer:{
  //  hot:true,
   hotOnly:true,
   contentBase:"./public",
  //  proxy:{
  //    '/api':{
  //      //http:localhost:8080/api/users -> https://api.github.com/api/users
  //      target:'https://api.github.com',
  //      //http:localhost:8080/api/users -> https://api.github.com/users
  //      pathRewrite:{
  //        '^/api':''
  //      },
  //      //不能使用localhost:8080 作为请求 Github 的主机名
  //      changeOrigin:true
  //    }
  //  }
  },
  module:{
    rules:[
      {
        test:/.css$/,
        use:[
          'style-loader',
          'css-loader'
        ]
      },
      {
        test:/.png$/,
        use:{
          loader:'file-loader',
          options:{
            limit:10 * 1024
          }
        }
      },
      {
        test: /\.html$/,
        use: {
          loader: 'html-loader',
          options: {
            attributes:{
              list:[
                {
                  tag: 'img',
                  attribute: 'src',
                  type: 'src',
                },
                {
                  tag: 'a',
                  attribute: 'href',
                  type: 'src',
                }
              ]
            }
          }
        }
      }
    ]
  },
  plugins:[
    // new CleanWebpackPlugin(),
    //用于生成index.html文件的
    new HtmlWebpackPlugin({
      title:'webpack plugin',
      meta:{
        viewport:'width=device-width'
      }
    }),
    new webpack.HotModuleReplacementPlugin(),
    // new CopyWebpackPlugin({
    //   patterns:[
    //     { from: 'public', to: './' },
    //   ]
    // }),
  ]
}

